<?php

namespace App\Model;

use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Http\Request;

/**
 * Class Salesmen
 *
 * @package App\Model
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Salesmen onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Salesmen withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Salesmen withoutTrashed()
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen query()
 * @property int $id 主键
 * @property string $name 负责人姓名
 * @property string $phone 电话
 * @property int $user_id 用户id
 * @property string $id_card 身份证
 * @property string|null $id_card_img 身份证照片
 * @property string $head_portrait 微信头像
 * @property string $open_id 微信open_id
 * @property string $bank_card_no 银行卡号
 * @property string $bank_card_name 开户人
 * @property string $bank_name 开户行
 * @property string $bank_branch 支行
 * @property int $place_partner_id 地区合伙人id
 * @property int $operator_id 运营商id
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 创建时间
 * @property string|null $deleted_at 删除时间
 * @property int $status
 * @property int $province_id 省份
 * @property int $city_id 城市id
 * @property int $area_id 区id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereAreaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereBankBranch($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereBankCardName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereBankCardNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereBankName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereCityId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereHeadPortrait($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereIdCard($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereIdCardImg($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereOpenId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereOperatorId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen wherePlacePartnerId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereProvinceId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Salesmen whereUserId($value)
 * @property-read \App\User $user
 */
class Salesmen extends Model
{
    use SoftDeletes;
    protected $table = 'salesmen';

    protected $fillable = ['name', 'phone', 'province_id', 'city_id', 'area_id', 'id_card', 'id_card_img', 'place_partner_id', 'operator_id', 'bank_name', 'bank_card_no', 'bank_card_name', 'bank_branch'];

    protected $hidden = ['deleted_at'];

    public function user()
    {
        return $this->hasOne(User::class, 'user_id', 'id');
    }

    public function getPaginate(Request $request, $where)
    {
        if ($request->has('province')) {
            $where['province'] = $request->input('request');
        }
        if ($request->has('city')) {
            $where['city'] = $request->input('city');
        }
        if ($request->has('name')) {
            $where['name'] = $request->input('name');
        }
        if ($request->has('phone')) {
            $where['phone'] = $request->input('phone');
        }
        $limit = request('limit', 15);
        return $this->where($where)->paginate($limit)->toArray();
    }
}
